<?php
namespace api\modules\v1\controllers;
use Yii;
use common\models\TradeWithdraw;
use common\models\Balance;
use common\models\WithdrawLog;
use common\models\Member;
use common\service\WithdrawService;
/*
	提现
*/

class WithdrawController extends CoreController
{
	/* 
		提现配置信息
		* b_type 
	*/
	public function actionConf()
	{
		$params = $this->request;
		$params['member_id'] = $this->_memberId;
		$params['b_type']      = $this->request('b_type');
		$data = WithdrawService::conf($params);
		$this->out('提现配置信息', $data);
	}


	/*
		提现申请
		* b_type 提现的帐本
		* password 交易密码
		* money  提现的金额
		* type   收款类型 wallet wechat alipay bank
		* address 收款类型为 wallet 是传入 
		* wechat 收款类型为wechat时传入
		* alipay 收款为alipay 时传入
		* bank_info 收款为bank时传入
	*/
	public function actionIndexInfo()
	{
		if(md5($this->request('password')) != $this->_member['paypwd']) $this->error('密码错误');
		if(!$this->_member['state']) $this->error('你暂不能此操作');

		$res = WithdrawService::apply($this->request, $this->_member);
		if(!$res['state']) $this->error($res['msg']);

		$this->out($res['msg']);
	}


	/* 
		* 提现记录
		* page 
		* page_size
		* b_type 选填
	*/

	public function actionList()
	{
		$where = array();
		$where['where'] = ['member_id'=>$this->_memberId];
		if($this->request('b_type')) $where['where']['b_type'] = $this->request('b_type');
		$params = array(
			'field' => ['*'],
			'page'	=> $this->request('page',1),
			'limit' => $this->request('page_size',10),
			'order' => 'id DESC'
		);
		$data = WithdrawLog::dataList($where, $params, ['collect']);
		$this->out('提现列表', $data);
	}


}